<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Action
 *
 * @author Sebastian
 */
class CMS_Controller_Action extends Zend_Controller_Action
{
	private $transalater = null;

	public function init()
	{
	    $this->detectLanguage();
		$this->transalater = Common_Translate::getDefaultDictionary(Common_Translate::getLanguage());
		$this->view->t = $this->transalater;
	}

    public function detectLanguage()
    {
      //$lang = $this->getParam("lang");
      $lang = $this->_request->getParams();
      $namespace = new Zend_Session_Namespace();
      $lang = $lang['lang'];
      if ( isset( $lang ) && $lang != '' ) // Si llega por request, se cambio el idioma
      {
        $namespace->lang = $lang;
        
        Common_Translate::setLanguage($lang);
      }
      elseif ( isset($namespace->lang) ) // si no viene por request, pero esta en sesion
      {
        Common_Translate::setLanguage($namespace->lang);
      }
      else // Idioma por defecto
      {
        $namespace->lang =  SYSTEM_DEFAULT_LANGUAGE;
        Common_Translate::setLanguage(SYSTEM_DEFAULT_LANGUAGE);
      }  
    } 
	
	
	public function _($key)
	{
		return $this->transalater->_($key);
	}

	public function getTranslater()
	{
		return $this->transalater;
	}

	public function disableAllViews()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
	}

	public function disableView()
	{
		$this->_helper->viewRenderer->setNoRender();
	}

	public function disableLayout()
	{
		$this->_helper->layout->disableLayout();
	}
}
?>
